package com.breeze.networkproject.volley;

import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.toolbox.StringRequest;
import com.breeze.networkproject.MyApp;

import java.util.Map;

/**
 * Volley请求的封装
 */
public class VolleyRequest {

    public static void requestGet(String url, Object tag, VolleyInterface volleyInterface) {
        MyApp.queues.cancelAll(tag);
        StringRequest request = new StringRequest(url, volleyInterface.getListener(), volleyInterface.getErrorListener());
        request.setTag(tag);
        MyApp.queues.add(request);
    }

    public static void requestPost(String url, Object tag, VolleyInterface volleyInterface, final Map<String, String> params) {
        MyApp.queues.cancelAll(tag);
        StringRequest request = new StringRequest(Request.Method.POST, url, volleyInterface.getListener(), volleyInterface.getErrorListener()) {
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                return params;
            }
        };
        request.setTag(tag);
        MyApp.queues.add(request);
    }
}
